*/
const { AccountsService, Clutter, Gio,
- GLib, GObject, Pango, Polkit, Shell, St } = imports.gi;
+ GLib, GObject, Pango, Polkit, Shell, St, UPowerGlib: UPower } = imports.gi;
const CheckBox = imports.ui.checkBox;
const Dialog = imports.ui.dialog;
const _ITEM_ICON_SIZE = 64;
+const LOW_BATTERY_THRESHOLD = 30;
+
const EndSessionDialogIface = loadInterfaceXML('org.gnome.SessionManager.EndSessionDialog');
const logoutDialogContent = {
const PkOfflineIface = loadInterfaceXML('org.freedesktop.PackageKit.Offline');
const PkOfflineProxy = Gio.DBusProxy.makeProxyWrapper(PkOfflineIface);
-const UPowerIface = loadInterfaceXML('org.freedesktop.UPower');
+const UPowerIface = loadInterfaceXML('org.freedesktop.UPower.Device');
const UPowerProxy = Gio.DBusProxy.makeProxyWrapper(UPowerIface);
function findAppFromInhibitor(inhibitor) {
this._powerProxy = new UPowerProxy(Gio.DBus.system,
'org.freedesktop.UPower',
- '/org/freedesktop/UPower',
+ '/org/freedesktop/UPower/devices/DisplayDevice',
(proxy, error) => {
if (error) {
log(error.message);
this._batteryWarning = new St.Label({
style_class: 'end-session-dialog-battery-warning',
- text: _('Running on battery power: Please plug in before installing updates.'),
+ text: _('Low battery power: please plug in before installing updates.'),
});
this._batteryWarning.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
this._batteryWarning.clutter_text.line_wrap = true;
this._user.disconnect(this._userChangedId);
}
+ _isDischargingBattery() {
+ return this._powerProxy.IsPresent &&
+ this._powerProxy.State !== UPower.DeviceState.CHARGING &&
+ this._powerProxy.State !== UPower.DeviceState.FULLY_CHARGED;
+ }
+
+ _isBatteryLow() {
+ return this._isDischargingBattery() && this._powerProxy.Percentage < LOW_BATTERY_THRESHOLD;
+ }
+
+ _shouldShowLowBatteryWarning(dialogContent) {
+ if (!dialogContent.showBatteryWarning)
+ return false;
+
+ if (!this._isBatteryLow())
+ return false;
+
+ if (this._checkBox.checked)
+ return true;
+
+ // Show the warning if updates have already been triggered, but
+ // the user doesn't have enough permissions to cancel them.
+ let updatesAllowed = this._updatesPermission && this._updatesPermission.allowed;
+ return this._updateInfo.UpdatePrepared && this._updateInfo.UpdateTriggered && !updatesAllowed;
+ }
+
_sync() {
let open = this.state == ModalDialog.State.OPENING || this.state == ModalDialog.State.OPENED;
if (!open)
if (dialogContent.subjectWithUpdates && this._checkBox.checked)
subject = dialogContent.subjectWithUpdates;
- if (dialogContent.showBatteryWarning) {
- this._batteryWarning.visible =
- this._powerProxy.OnBattery && this._checkBox.checked;
- }
+ this._batteryWarning.visible = this._shouldShowLowBatteryWarning(dialogContent);
let description;
let displayTime = _roundSecondsToInterval(this._totalSecondsToStayOpen,
if (dialogContent.showOtherSessions)
this._loadSessions();
- let updateTriggered = this._updateInfo.UpdateTriggered;
- let updatePrepared = this._updateInfo.UpdatePrepared;
let updatesAllowed = this._updatesPermission && this._updatesPermission.allowed;
_setCheckBoxLabel(this._checkBox, dialogContent.checkBoxText || '');
- this._checkBox.visible = dialogContent.checkBoxText && updatePrepared && updatesAllowed;
- this._checkBox.checked = this._checkBox.visible;
-
- // We show the warning either together with the checkbox, or when
- // updates have already been triggered, but the user doesn't have
- // enough permissions to cancel them.
- this._batteryWarning.visible = dialogContent.showBatteryWarning &&
- (this._checkBox.visible || updatePrepared && updateTriggered && !updatesAllowed);
+ this._checkBox.visible = dialogContent.checkBoxText && this._updateInfo.UpdatePrepared && updatesAllowed;
+
+ if (this._type === DialogType.UPGRADE_RESTART)
+ this._checkBox.checked = this._checkBox.visible && this._updateInfo.UpdateTriggered && !this._isDischargingBattery();
+ else
+ this._checkBox.checked = this._checkBox.visible && !this._isBatteryLow();
+
+ this._batteryWarning.visible = this._shouldShowLowBatteryWarning(dialogContent);
this._updateButtons();